package xing.application.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import xing.application.api.client.PmsClient;

import javax.servlet.http.HttpUtils;
import java.net.URLEncoder;
import java.text.MessageFormat;

@Service
public class AiStewardApi {
    @Autowired
    PmsClient pmsClient;

    private @Value("${web.wechat.appId}") String appId;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * @Description:智能管家列表
     * @param:  * @param null
     * @Author: dustin
     * @Date: 2017-10-26
     */
    public String getAiStewardList(String phone,int pageNo,int pageSize,String searchText,String searchType,String compositeName,String compositeType) throws Exception{

        String para= MessageFormat.format("phoneNum={0}&pageNo={1}&pageSize={2}",phone,pageNo,pageSize);
        if(!StringUtils.isEmpty(searchText))
            para=para+"&searchText="+ URLEncoder.encode(searchText,"UTF-8");
        if(!StringUtils.isEmpty(searchType))
            para=para+"&searchType="+searchType;
        if(!StringUtils.isEmpty(compositeName))
            para=para+"&compositeName="+compositeName;
        if(!StringUtils.isEmpty(compositeType))
            para=para+"&compositeType="+compositeType;

        String str= pmsClient.getCommand("wxapi/getITeventList", para);
        return str;
    }

    //获取详情
    public String getDetail(int id,String phone){
        String str= pmsClient.getCommand("it/tevent/info.html",
                MessageFormat.format("eventid={0}&phoneNum={1}",id+"",phone));
        return str;
    }
    //获取状态统计信息
    public String getAiStewardStatusSummery(String phone){
        String str= pmsClient.getCommand("wxapi/getITeventCount",
                MessageFormat.format("phoneNum={0}",phone));
        return str;
    }
}
